package _07_串;

import java.util.Arrays;

public class _242_有效的字母异位词 {

    // 计数法
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) return false;
        char[] char1 = s.toCharArray();
        char[] char2 = t.toCharArray();
        int[] ints = new int[26];
        for (char c : char1) {
            ints[c - 'a']++;
        }

        for (char c : char2) {
            if (--ints[c - 'a'] < 0) return false;
        }
        return true;
    }

    // 字符排序法则
    public boolean isAnagram1(String s, String t) {
        if (s.length() != t.length()) return false;
        char[] char1 = s.toCharArray();
        char[] char2 = t.toCharArray();

        Arrays.sort(char1);
        Arrays.sort(char2);
        return Arrays.equals(char1, char2);
    }

}
